//
//  EPMBottomBtnView.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/4/5.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "EPMBottomBtnView.h"

@interface EPMBottomBtnView()
@property (weak,nonatomic) UIButton* emotionBtn;
@end

@implementation EPMBottomBtnView
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]){
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"compose_toolbar_background"]];
    UIButton* pictureBtn = [self setBtnWithImg:@"compose_toolbar_picture" type:Picture];
    [self addSubview:pictureBtn];
    UIButton* mentionBtn = [self setBtnWithImg:@"compose_mentionbutton_background" type:mention];
    [self addSubview:mentionBtn];
    UIButton* trendBtn = [self setBtnWithImg:@"compose_trendbutton_background" type:trend];
    [self addSubview:trendBtn];
    UIButton* emotionBtn = [self setBtnWithImg:@"compose_emoticonbutton_background" type:emotion];
    _emotionBtn = emotionBtn;
    [self addSubview:emotionBtn];
    UIButton* addBtn = [self setBtnWithImg:@"compose_add_background" type:add];
    [self addSubview:addBtn];
    
    [pictureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.bottom.equalTo(self);
        make.width.equalTo(mentionBtn);
    }];
    [mentionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.leading.equalTo(pictureBtn.mas_trailing);
        make.width.equalTo(trendBtn);
    }];
    [trendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.leading.equalTo(mentionBtn.mas_trailing);
        make.width.equalTo(emotionBtn);
    }];
    [emotionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.leading.equalTo(trendBtn.mas_trailing);
        make.width.equalTo(addBtn);
    }];
    [addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.trailing.equalTo(self);
        make.leading.equalTo(emotionBtn.mas_trailing);
    }];
    
}

- (UIButton*)setBtnWithImg:(NSString*)imgName type:(ComposeBtnType)type{
    UIButton* btn = [[UIButton alloc]init];
    [btn setImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imgName]] forState:UIControlStateHighlighted];
    btn.tag = type;
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    return btn;
    
}
- (void)setEmotionBtnName:(NSString *)emotionBtnName{
    _emotionBtnName = emotionBtnName;
    [self.emotionBtn setImage:[UIImage imageNamed:emotionBtnName] forState:UIControlStateNormal];
    [self.emotionBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",emotionBtnName]] forState:UIControlStateHighlighted];
}


- (void)btnClick:(UIButton*)sender{
    self.btnClickBlock(sender.tag);
}
@end
